//
//  SRRegisterView.m
//  SportRing
//
//  Created by Apple on 14/10/23.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRRegisterView.h"

//@implementation SRRegisterViewModel
//
//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        self.cellModels = [NSMutableArray array];
//    }
//    return self;
//}
//
//@end

@interface SRRegisterView ()

@property (nonatomic, weak) IBOutlet LGButton * registerBtn;
@property (nonatomic, weak) IBOutlet UIButton * gotoLoginBtn;
@property (nonatomic, weak) IBOutlet UILabel * gotoLoginLabel;
@property (nonatomic, weak) IBOutlet UITableView * tableView;
@property (nonatomic, weak) IBOutlet UITextField * nickNameTF;
@property (nonatomic, weak) IBOutlet UITextField * mobileTF;
@property (nonatomic, weak) IBOutlet UITextField * passwordTF;

@end

@implementation SRRegisterView

-(void)awakeFromNib
{
    [super awakeFromNib];
    
    [self setupButtons];
    
    @weakify(self);
    if (!([UIScreen mainScreen].bounds.size.height > 480)) {
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"registerBg480"]];
    }else
    {
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"registerBg"]];
    }
    
    self.tableView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    self.tableView.layer.borderWidth = 1.0;
    self.tableView.backgroundColor = [UIColor clearColor];
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"已注册,直接登录"];
//    [str addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0,8)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0,8)];
    
    self.gotoLoginLabel.attributedText = str;
    self.gotoLoginLabel.textAlignment = NSTextAlignmentCenter;
    RAC(self.registerBtn, enabled) = [RACSignal combineLatest:@[self.nickNameTF.rac_textSignal,
                                                                self.mobileTF.rac_textSignal,
                                                                self.passwordTF.rac_textSignal]
                                                       reduce:^(NSString *nickName, NSString * mobile, NSString *password) {
                                                           return @(nickName.length > 0 && mobile.length > 0 && password.length > 0);
                                                       }];
    
    [[self.registerBtn rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(id x) {
         [self_weak_.delegate doRegisterActionWithNickName:self_weak_.nickNameTF.text
                                                    mobile:self_weak_.mobileTF.text
                                                  password:self_weak_.passwordTF.text];
    }];
    
    [[self.gotoLoginBtn rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(id x) {
         [self_weak_.delegate doGotoLoginView];
     }];
}

//-(void)setViewModel:(SRRegisterViewModel *)viewModel
//{
//    _viewModel = viewModel;
//    [self.tableView reloadData];
//}

- (void)setupButtons
{
//    LGButtonColorPair * normalColor1 = [LGButtonColorPair colorPairWithTitleColor:[UIColor whiteColor]
//                                                                   backgroundColor:[UIColor colorWithRed:113.0/255.0
//                                                                                                   green:183.0/255.0
//                                                                                                    blue:20.0/255.0
//                                                                                                   alpha:1.0f]];
//    [self.registerBtn setColorPairs:@{@(LG_BUTTON_STATE_TYPE_NORMAL):normalColor1}];
}

#pragma mark - UITableViewDataSource ,UITableViewDelegate

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    return 1;
//    
//}
//
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
//    
//    
//    return [_viewModel.cellModels count] >0 ?[_viewModel.cellModels count] : 0;
//    
//}
//
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    
//    SRRingTableViewCell *silenceCell = [tableView dequeueReusableCellWithIdentifier:@"SRRingTableViewCell"];
//    
//    SRRingTableViewCellModel *model = (SRRingTableViewCellModel *)[_viewModel.cellModels objectAtIndex:indexPath.row];
//    
//    [silenceCell setSRRingTableViewCellData:model];
//    
//    return silenceCell;
//    
//}
//
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    SRRingTableViewCell *cell = (SRRingTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
//    
//    cell.selected = YES;
//    
//    if (_delegate && [_delegate respondsToSelector:@selector(selectedRing:)])
//    {
//        SRRingTableViewCellModel * cellModel = self.viewModel.cellModels[indexPath.row];
//        [_delegate selectedRing:cellModel.ringIdSting];
//    }
//}

@end
